*This file performs the industry level analysis in Finland. Creates Tables 2 and 3. 

use "$path/industry_data.dta", clear

**Table 2

*Define global exposure variable
global b_treat  treat_std_l

reg  ln_value_prod $b_treat if year==1943, r
reg  lnlabor_all $b_treat if year==1943, r
reg  power_labor_share $b_treat if year==1943, r
reg  ln_relative_wage $b_treat if year==1943, r
reg  ln_establishments $b_treat if year==1943, r
reg  skilled_labor_share $b_treat if year==1943, r
reg  ln_inputs_all $b_treat if year==1943, r
reg  ln_valueadded $b_treat if year==1943, r

foreach x in ln_value_prod lnlabor_all  power_labor_share ln_relative_wage ln_establishments skilled ln_inputs_all ln_valueadded{
gen change_`x'=`x'1943-`x'1934
}

foreach x in ln_value_prod lnlabor_all  power_labor_share ln_relative_wage ln_establishments skilled ln_inputs_all ln_valueadded{
reg change_`x' $b_treat if year==1943, r
}

rename skilled_labor_share skilled

*Lable variables 

label variable repa_sharel "Reparations share"
label variable ln_value_prod "ln Value of production"
label variable lnlabor_all "ln Labor"
label variable power_labor_share "Power labor share"
label variable ln_relative_wage "ln Average wage"
label variable ln_establishments "ln Establishments"
label variable skilled "Skilled labor share"
label variable ln_inputs_all "ln Value of inputs"
label variable ln_valueadded "ln Value added"


*Covariate balance

foreach var of varlist repa_sharel ln_value_prod lnlabor_all power_labor_share ln_relative_wage  ln_establishments  skilled  ln_inputs_all ln_valueadded {
	*Summary statistics
	sum `var' if year==1943
	local mean_`var'=r(mean)
	local min_`var'= r(min)
	local max_`var' = r(max)
	local sd_`var'=r(sd)
	local N`var'=r(N)

	*Format numbers
	local N`var': di %12.0gc `N`var''
	local mean_`var': di %3.2f `mean_`var''
	local min_`var': di %3.2f `min_`var''
	local max_`var': di %3.2f `max_`var''
	local sd_`var': di %3.2f `sd_`var''


	*Reg levels of dependent variables
	reg `var' $b_treat if year==1943, r
	local b_`var'=_b[$b_treat]
	local se_`var'=_se[$b_treat]
	local t_`var' = _b[$b_treat]/_se[$b_treat]
	local p_`var' = 2*ttail(e(df_r), abs(`t_`var''))

	local star_`var'= cond(`p_`var''<0.01,"***", cond(`p_`var''<0.05,"**", cond(`p_`var''<0.10,"*", "")))

	*Format numbers
	local b_`var': di %3.2f `b_`var''
	local se_`var': di %3.2f `se_`var''
	local p_`var': di %12.3fc `p_`var''
	local t_`var': di %12.3fc `t_`var''
	
	*Variable name
	local label_`var': var label `var'	
}

*Reg changes in dependent variables 
foreach x in ln_value_prod lnlabor_all power_labor_share ln_relative_wage  ln_establishments  skilled ln_inputs_all ln_valueadded {
	
	reg change_`x' $b_treat if year==1943, r
	local bc_`x'=_b[$b_treat]
	local sec_`x'=_se[$b_treat]
	local tc_`x' = _b[$b_treat]/_se[$b_treat]
	local pc_`x' = 2*ttail(e(df_r), abs(`tc_`x''))
	
	local starc_`x'= cond(`pc_`x''<0.01,"***", cond(`pc_`x''<0.05,"**", cond(`pc_`x''<0.10,"*", "")))
	
	*Format numbers
	local bc_`x': di %3.2f `bc_`x''
	local sec_`x': di %3.2f `sec_`x''
	local pc_`x': di %12.3fc `pc_`x''
	local tc_`x': di %12.3fc `tc_`x''
}


*OUTPUT TO LATEX

texdoc init "$tables/industry_balance.tex", replace force

tex \begin{tabular}{lcccccc} \toprule
tex  & Mean &  Min & Max &  $\beta^{Reparations \: share}$ &  $\beta^{Changes}$ &  Observations \\
tex  & (1) &  (2) & (3) &  (4) &  (5) &  (6) \\

tex \addlinespace \hline

local var repa_sharel
tex `label_`var'' 	& `mean_`var'' 	& `min_`var''	& `max_`var''	 & 	& 	& `N`var''	\\
tex  	& [`sd_`var'']  & 	& 	& 	 &   &  	\\


foreach var of varlist power_labor_share skilled  lnlabor_all ln_valueadded ln_relative_wage ln_establishments  ln_inputs_all {
	tex `label_`var'' 	& `mean_`var'' 	& `min_`var''	& `max_`var''	 & `b_`var''`star_`var''	& `bc_`var''`starc_`var''	& `N`var''	\\
	tex  	& [`sd_`var'']  & 	& 	& (`se_`var'')	 &  (`sec_`var'') &  	\\
}


local var "ln_value_prod"
tex `label_`var'' 	& `mean_`var'' 	& `min_`var''	& `max_`var''	 & `b_`var''`star_`var''	& `bc_`var''`starc_`var''	& `N`var''	\\
tex  	& [`sd_`var'']  & 	& 	& (`se_`var'')	 &  (`sec_`var'') &  	\\   \bottomrule

tex \end{tabular}
texdoc close


**Table 3

*Reparations share measure
foreach var in ln_value_prod lnlabor_all ln_valueadded {

reghdfe `var' scaledpost , absorb(year isic $sharecontrols) vce(cluster isic) 
estadd local ii "162"
estimates store `var's1 
estadd local established "None"
estadd local ife "\checkmark"
estadd local yfe "\checkmark"

reghdfe `var'  scaledpost  if timberpaper==0  , absorb(year isic $sharecontrols) vce(cluster isic) 
estadd local ii "142"
estimates store `var's2
estadd local established "Established"
estadd local ife "\checkmark"
estadd local yfe "\checkmark"
}

*Linear measure 
foreach var in ln_value_prod lnlabor_all ln_valueadded {


reghdfe `var' linearpost , absorb(year isic $linearcontrols) vce(cluster isic) 
estadd local ii "162"
estimates store `var'l1 
estadd local established "None"
estadd local ife "\checkmark"
estadd local yfe "\checkmark"

reghdfe `var'  linearpost  if timberpaper==0  , absorb(year isic $linearcontrols) vce(cluster isic) 
estadd local ii "142"
estimates store `var'l2
estadd local established "Established"
estadd local ife "\checkmark"
estadd local yfe "\checkmark"
}

	
*Different skill-intensity in industries

*Use data on average industry education levels. See paper for details

preserve
use "$path/ind_edu.dta", clear
tempfile education
gen low_edu=(high_edu!=1)
save `education' 
restore

*drop _merge
joinby digt2 using `education' , unmatched (master) 

preserve
keep if year==1943

*only for the treated
replace high_edu=0 if high_edu==.&repa_sharel==0
replace low_edu=0 if low_edu==.&repa_sharel==0

gen h_std=(repa_sharel*high_edu)
egen h_std2=std(repa_sharel*high_edu)

gen l_std=(repa_sharel*low_edu)
egen l_std2=std(repa_sharel*low_edu)

gen hs_linear=ln_repa_tot*high_edu
gen ls_linear=ln_repa_tot*low_edu

gen high_skill_treated=(h_std>0)
gen low_skill_treated=(l_std>0)

keep isic h_std h_std2 l_std l_std2 low_edu high_edu hs_linear ls_linear high_skill_treated low_skill_treated
tempfile education2
save `education2' 

restore

drop _merge
joinby isic using `education2' , unmatched (master) 

gen high_skill_post=h_std2*post
gen low_skill_post=l_std2*post

label var high_skill_post "HS x Reparations share x Post"
label var low_skill_post "LS x Reparations share x Post"
	
*only for the treated
replace high_edu=0 if high_edu==.&repa_sharel==0

global edu_controls high_edu#year 

*Interacted controls
global controls43h c.power_labor_share1943#year#high_edu    ///
 c.ln_value_prod1943#year#high_edu  c.lnlabor_all1943#year#high_edu c.ln_relative_wage1943#year#high_edu c.ln_establishments1943#year#high_edu c.skilled1943#year#high_edu c.ln_inputs_all1943#year#high_edu c.ln_valueadded1943#year#high_edu 
 

foreach var in ln_value_prod lnlabor_all ln_valueadded {

preserve

drop scaledpost
gen scaledpost=high_skill_post

reghdfe `var'   scaledpost if timberpaper==0&low_skill_treated==0 , absorb(year isic $sharecontrols) vce(cluster isic) 
estadd local ii "133"
estimates store `var'hl1 
estadd local ife "\checkmark"
estadd local yfe "\checkmark"
estadd local established "\begin{tabular}{@{}l@{}} Established+\\ LS Exposed\\\end{tabular}"
restore

preserve
drop scaledpost
gen scaledpost=low_skill_post
reghdfe `var'   scaledpost if timberpaper==0&high_skill_treated==0 , absorb(year isic $sharecontrols) vce(cluster isic) 
estadd local ii "121"
estimates store `var'hl2
estadd local established "\begin{tabular}{@{}l@{}} Established+\\ HS Exposed\\\end{tabular}"
estadd local ife "\checkmark"
estadd local yfe "\checkmark"
restore

reghdfe `var'   high_skill_post low_skill_post, absorb(year isic $sharecontrols) vce(cluster isic) 
estadd local ii "162"
estimates store `var'hl3 
estadd local established "None"
estadd local ife "\checkmark"
estadd local yfe "\checkmark"

reghdfe `var'    high_skill_post low_skill_post if timberpaper==0   , absorb(year   isic $sharecontrols) vce(cluster isic) 
estadd local ii "142"
estimates store `var'hl4
estadd local established "Established"
estadd local ife "\checkmark"
estadd local yfe "\checkmark"
}

global table industry_results
	
esttab ln_value_prods1  ln_value_prods2 ln_value_prodl1  ln_value_prodl2    ln_value_prodhl1  ln_value_prodhl2  ln_value_prodhl3  ln_value_prodhl4   using "$tables/$table.tex", replace booktabs  mlabels(none) ///
mgroups("Panel A: ln Value of production"  , pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) ) ///
	compress lines star(* .1 ** .05 *** .01) label ///
	b(%9.3f) se(%9.3f) stats(N , labels("\textit{N}") ///
	fmt(0 2)) keep(scaledpost linearpost high_skill_post low_skill_post  )  nodepvars nomtitle ///
	prehead(\begin{tabular}{l*{8}{c}} \toprule) ///
	postfoot(\midrule)
		
esttab  lnlabor_alls1  lnlabor_alls2 lnlabor_alll1  lnlabor_alll2    lnlabor_allhl1  lnlabor_allhl2  lnlabor_allhl3  lnlabor_allhl4   using "$tables/$table.tex", append booktabs  mlabels(none) ///
mgroups("Panel B: ln Labor force"  , pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) ) ///
	compress lines star(* .1 ** .05 *** .01) label ///
	b(%9.3f) se(%9.3f) stats(N , labels("\textit{N}") ///
	fmt(0 2)) keep(scaledpost linearpost high_skill_post low_skill_post )  nodepvars nomtitle ///
	prehead("") ///
	postfoot(\midrule)
		
esttab  ln_valueaddeds1  ln_valueaddeds2 ln_valueaddedl1  ln_valueaddedl2    ln_valueaddedhl1  ln_valueaddedhl2  ln_valueaddedhl3  ln_valueaddedhl4     using "$tables/$table.tex", append booktabs  mlabels(none) ///
mgroups("Panel C: ln Value added"   , pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}) ) ///
	compress lines star(* .1 ** .05 *** .01) label ///
	b(%9.3f) se(%9.3f) stats(N ii ife yfe established  , labels( "\textit{N}" "Industries" "Industry FE" "Year FE" "Omitted")  ///
	fmt(0 2)) keep(scaledpost linearpost high_skill_post low_skill_post )  nodepvars nomtitle ///
	prehead("") ///
	postfoot(\bottomrule \end{tabular})
	
save   "$path/industry_data_temp.dta", replace

